/**
 * 
 */
package com.mycompany.client.widgets;

import com.mycompany.shared.EnvConstants;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.PickerIcon;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.FormItemClickHandler;
import com.smartgwt.client.widgets.form.fields.events.FormItemIconClickEvent;

/**
 * @author coral.ma
 *
 */
public class CoralCodeItem extends TextItem {

	private PickerIcon searchPicker = new PickerIcon(PickerIcon.SEARCH);
	private String tableName;
	private String whereClause;
	private String[] parameters;
	private String[] gridTitles;
	private FormItem relatedItem;

	public CoralCodeItem(String name, String title, String tableName, String[] parameters, String[] gridTitles) {
		this(name,title,tableName,"",parameters,gridTitles);
	}
	
	public CoralCodeItem(String name, String title, String tableName, String[] parameters, String[] gridTitles, FormItem relatedItem) {
		this(name,title,tableName, "", parameters, gridTitles, relatedItem);
	}

	public CoralCodeItem(String name, String title, String tableName, String whereClause, String[] parameters, String[] gridTitles) {
		this(name,title,tableName,whereClause,parameters,gridTitles, null);
	}

	public CoralCodeItem(String name, String title, String tableName, String whereClause, String[] parameters, String[] gridTitles, FormItem relatedItem) {
		setName(name);
		setTitle(title);
		setIcons(searchPicker);
		setWidth(EnvConstants.CORAL_ITEM_WIDTH);
		this.tableName = tableName;
		this.whereClause = whereClause;
		this.parameters = parameters;
		this.gridTitles = gridTitles;
		this.relatedItem = relatedItem;
		addFormItemClickHandler();
	}
	
	public CoralCodeItem(String name, String title) {
		setName(name);
		setTitle(title);
		setIcons(searchPicker);
		setWidth(EnvConstants.CORAL_ITEM_WIDTH);
		addFormItemClickHandler();
	}
	
	private void addFormItemClickHandler() {
		searchPicker.addFormItemClickHandler(new FormItemClickHandler() {
			public void onFormItemClick(FormItemIconClickEvent event) {
				SC.say("Search Picker clicked");  
			}
		});
	}

	/**
	 * @return the searchPicker
	 */
	public PickerIcon getSearchPicker() {
		return searchPicker;
	}

	/**
	 * @param searchPicker the searchPicker to set
	 */
	public void setSearchPicker(PickerIcon searchPicker) {
		this.searchPicker = searchPicker;
	}

	/**
	 * @return the tableName
	 */
	public String getTableName() {
		return tableName;
	}

	/**
	 * @param tableName the tableName to set
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	/**
	 * @return the whereClause
	 */
	public String getWhereClause() {
		return whereClause;
	}

	/**
	 * @param whereClause the whereClause to set
	 */
	public void setWhereClause(String whereClause) {
		this.whereClause = whereClause;
	}

	/**
	 * @return the gridTitles
	 */
	public String[] getGridTitles() {
		return gridTitles;
	}

	/**
	 * @param gridTitles the gridTitles to set
	 */
	public void setGridTitles(String[] gridTitles) {
		this.gridTitles = gridTitles;
	}

	/**
	 * @return the parameters
	 */
	public String[] getParameters() {
		return parameters;
	}

	/**
	 * @param parameters the parameters to set
	 */
	public void setParameters(String[] parameters) {
		this.parameters = parameters;
	}

	/**
	 * @return the relatedItem
	 */
	public FormItem getRelatedItem() {
		return relatedItem;
	}

	/**
	 * @param relatedItem the relatedItem to set
	 */
	public void setRelatedItem(FormItem relatedItem) {
		this.relatedItem = relatedItem;
	}
}
